public class Main {
    private final  static Object locker=new Object();
    static int count=1;
    static int limit=100;
    public static class test implements Runnable{
        @Override
        public void run() {
            synchronized (locker) {
                while(count<limit) {
                    System.out.println(Thread.currentThread().getName()+":"+count);
                    count++;
                    //唤醒全部线程
                    locker.notifyAll();
                    try {
                        //让这个线程进行阻塞
                        locker.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
    public static void main1(String[] args) {
        Thread t1=new Thread(new test(),"thread-01");
        Thread t2=new Thread(new test(),"thread-02");
        t1.start();
        t2.start();
    }
}